#coding:utf8
from random import randint

data = [randint(0, 30) for _ in range(30)]
print (data)

# 统计列表中每个元素出现的频率 以字典的形式返回

#方法一
c1 = dict.fromkeys(data, 0)
print(c1)

for x in data:
    c1[x] += 1

print(c1)

#方法二
from collections import Counter
c2 = Counter(data)
print(c2)
#出现频率最高的3个
print(c2.most_common(3))




#分析某文章中出现次数最高的10个单词
import re
text = open('test.txt').read()
print(text)
text = re.split('\W', text)
print(text)
c3 = Counter(text)
print(c3)
print(c3.most_common(3))






